package com.yunxi.controller.approve;

import com.github.pagehelper.PageInfo;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import com.yunxi.order.pojo.VehicleReturApplyVerifyReqVO;
import com.yunxi.order.pojo.VehicleReturCheckQueryReqVO;
import com.yunxi.order.pojo.VehicleReturCheckQueryRespVO;
import com.yunxi.order.service.VehicleReturApplyDubboService;
import com.yunxi.stock.pojo.PartnerStockOutReqVO;
import com.yunxi.stock.pojo.PartnerStockOutRespVO;
import com.yunxi.stock.pojo.PartnerStockOutSignInReqVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wholesale/vehicleReturApplyApprove")
@Api(tags = "wholesale:vehicleReturApplyApprove", description = "渠道商申请退车接口")
public class VehicleReturApplyApproveController {

    @Autowired
    VehicleReturApplyDubboService vehicleReturApplyDubboServiceImpl;

    @ApiOperation(value = "审核")
    @PostMapping(value = "/applyReturVehicle")
    public ApiResult<Boolean> verify(@CurrentUser LoginInfo user, @RequestBody VehicleReturApplyVerifyReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());

        boolean isSuccess = vehicleReturApplyDubboServiceImpl.verify(vo);
        return ResponseUtil.ok(isSuccess);
    }

    @ApiOperation(value = "审核数据查询")
    @GetMapping(value = "/queryByList")
    public ApiResult<VehicleReturCheckQueryRespVO> queryByList(@CurrentUser LoginInfo user,VehicleReturCheckQueryReqVO vo, int pageNum, int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        vo.setUserCode(user.getUserCode());

        PageInfo<VehicleReturCheckQueryRespVO> pageInfo = vehicleReturApplyDubboServiceImpl.queryByList(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "主机厂退车数据查询")
    @GetMapping(value = "/queryPartnerStockOut")
    public ApiResult<PartnerStockOutRespVO> queryPartnerStockOut(@CurrentUser LoginInfo user,PartnerStockOutReqVO vo,int pageNum,int pageSize){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }

        PageInfo<PartnerStockOutRespVO> pageInfo = vehicleReturApplyDubboServiceImpl.queryPartnerStockOut(vo,pageNum,pageSize);
        return ResponseUtil.ok(pageInfo);
    }

    @ApiOperation(value = "主机厂接收退车")
    @PostMapping(value = "/signIn")
    public ApiResult<Boolean> signIn(@CurrentUser LoginInfo user,@RequestBody PartnerStockOutSignInReqVO vo){
        Object partnerVO = (Object) user.getPartner();
        if(partnerVO != null){
            //
            //表示当前用户是主机厂
            return ResponseUtil.fail(401,"当前用户不是主机厂用户，请使用主机厂用户登录！");
        }
        vo.setUserCode(user.getUserCode());
        boolean isSuccess = vehicleReturApplyDubboServiceImpl.signIn(vo);

        return ResponseUtil.ok(isSuccess);
    }
}
